public class TestLambda {
    public static void main(String[] args) {
        testA();
        testB();
        testC();
        testD();
    }
    public static void testD(){
        //创建D接口的匿名内部类对象
        D d1 = new D() {
            @Override
            public int max(int a, int b) {
                return a > b ? a : b;
            }
        };
        //将匿名内部类对象改成Lambda表达式
        D d2 = (a, b) -> a > b? a : b;
        int max = d1.max(10, 20);
        System.out.println(max);
        //调用max方法
        D d3 = Math::max;
        int max2 = d3.max(10, 20);
        System.out.println(max2);
    }
    public static void testC(){
        //创建C接口的匿名内部类对象
        C c1 = name -> "name =" + name;
        String s = c1.show("xiaoming");
        System.out.println(s);
        //调用show4方法
        C c2 = TestLambda::show4;
        String s1 = c2.show("xiaohong");
        System.out.println(s1);
    }
    public static void testB(){
        //创建B接口的匿名内部类对象
        B b1 = new B() {
            @Override
            public void show(String name) {
                System.out.println(name);
            }
        };
        //将匿名内部类对象改成Lambda表达式
        B b2 = System.out::println;
        b1.show("肖博文同学");
    }
    public static void testA(){
        //创建A接口的匿名内部类对象
        A a1 = new A() {
            @Override
            public void show(String name, int age) {
                System.out.println(name + " " + age);
            }
        };
        //将匿名内部类对象改成Lambda表达式
        A a2 = ( name, age) -> System.out.println(name + " " + age);
        a1.show("zhangsan", 20);

        //调用show2方法
        A a3 = TestLambda::show2;
        a3.show("lisi", 18);

        A a4 = new TestLambda()::show3;
        a4.show("wangwu", 22);

    }
    //定义一个成员方法，故意让返回值和形参和A接口中的方法一致
    public  static void show2(String name, int age){
        System.out.println("show2:" + name + " " + age);
    }
    public void show3(String name, int age){
        System.out.println("show3:" + name + " " + age);
    }
    public static String show4(String name){
        return "name = " + name;
    }
}
